package com.ybox.crawler.api.factory;

import com.ybox.common.core.domain.R;
import com.ybox.crawler.api.service.RemoteCrawlerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文件服务降级处理
 *
 * @author ych
 */
@Component
public class RemoteCrawlerFallbackFactory implements FallbackFactory<RemoteCrawlerService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCrawlerFallbackFactory.class);

    @Override
    public RemoteCrawlerService create(Throwable throwable) {
        log.error("爬虫服务调用失败:{}", throwable.getMessage());
        return new RemoteCrawlerService() {
            @Override
            public R<String> getArticleFromUrl(String url) {
                return R.fail("从" + url + "获取文章失败:" + throwable.getMessage());
            }
        };
    }
}
